<template>
  <div class="list-page">
    <tool-bar nav="" title="应用部署设置服务器">
      <el-button @click="$router.push('/dev/user-dockerfile/list')">自定义Dockerfile</el-button>
      <el-button @click="$router.push('/dev/user-k8s-deployment/list')">自定义K8sDeployment</el-button>
      <el-button @click="add_click()">添加</el-button>
    </tool-bar>
    <my-list
        ref="list"
        url="/dev/app-deploy-setting/list"
        @param="preload"
        @loaded="procData"
        :page-size="10"
        :store="true"
    >

      <el-table-column align="center" label="环境编码" prop="code" width="180">
        <template v-slot="scope">
          <el-tag effect="dark" type="primary" v-if="scope.row.isActive">{{ scope.row.code }}</el-tag>
          <div v-else>{{ scope.row.code }}</div>
        </template>
      </el-table-column>
      <el-table-column label="环境名称" align="center" width="180">
        <template v-slot="scope">
          <div class="link" @click="edit_click(scope.row)">{{ scope.row.name }}</div>
        </template>
      </el-table-column>

      <el-table-column align="center" label="jenkins调用中台接口" prop="mpIntegrationApiHost"></el-table-column>

      <el-table-column label="操作" align="center">
        <template v-slot="scope">
          <el-button type="primary" plain round @click="set_click(scope.row)" size="small"
                     v-if="!scope.row.isActive">
            激活当前项
          </el-button>

          <el-tag effect="dark" type="primary" v-else style="margin:12px;">当前为激活项</el-tag>

          <el-button type="warning" plain round @click="delete_click(scope.row)" size="small">
            删除
          </el-button>
        </template>
      </el-table-column>
      <template #query="scope">
        <kv label="名称">
          <el-input v-model="scope.query.name"></el-input>
        </kv>
      </template>
    </my-list>
    <!--        <el-alert-->
    <!--            v-if="userSetting"-->
    <!--            :title="'用户设置了: ' + userSetting"-->
    <!--            type="error"-->
    <!--            :closable="false">-->
    <!--        </el-alert>-->
  </div>
</template>

<script setup>
/**
 * Created by CodeGenerator at 2022-04-29 15:19:26
 */
import card from "./app-deploy-setting-card.vue"


//定义 vue2的this,当前组件
const $self = getCurrentInstance();

//定义 $attrs
const $attrs = useAttrs();


//定义data
const $data = reactive({});


const $props = defineProps({});


const list = ref();

//定义事件
const $emit = defineEmits(["update:modelValue", "loaded"]);


const set_click = function (row) {
  var url = "/dev/app-deploy-setting/set-active?id=" + row.id
  jv.$http.post(url).then(res => {
    top.location.reload();
  })
};
const preload = function (param) {
//添加查询参数，修改分页参数等。
//param.type = jv.$route.params.type
};
const procData = function (res) {
  res.data.data.forEach(it => {
//如果是组合实体，设置 it.id=...
  });
};
const loadData = function (pageNumber) {
  list.value.loadData(pageNumber);
};
const add_click = function () {
  jv.$router.push("/dev/app-deploy-setting/add")
};
const edit_click = function (row) {
//记录上次点击行
  var rowId = row.id;
  list.value.setLastRow(row);
  jv.$router.push("/dev/app-deploy-setting/edit/" + rowId)
};
const delete_click = async function (row) {
  var rowId = row.id, rowName = row.name;
  await jv.confirm('确认删除 ' + rowName + ' 吗？');
  var res = await jv.$http.post("/dev/app-deploy-setting/delete/" + rowId)
  loadData();
};

onMounted(function () {
// var url = jv.getFullUrl(jv.SERVER_INTEGRATION_HOST) + "/dev/app-deploy-setting/current"
// jv.$http.get(url).then(res => {
// 	this.current = res.data.data;
// })
})


</script>